﻿Ext.define('Oa.PasswordWin', {
    extend: 'Ext.window.Window',
    id: 'pwdWin', title: '修改密码', width: 330, layout: 'form', modal: true, frame: true, resizable: false,
    buttons: [{
        text: '确定', id: 'btnConfirm',
        handler: function () {
            var pwdForm = Ext.getCmp('pwdForm');
            if (!pwdForm.form.findField('oldPwd').isValid() || !pwdForm.form.findField('newPwd').isValid()) {
                Ext.Msg.alert('提示', '原始密码或新密码不能为空！');
                return;
            }
            if (pwdForm.form.findField('newPwd').getValue() != pwdForm.form.findField('surePwd').getValue()) {
                Ext.Msg.alert('提示', '两次输入密码不一致！');
                return;
            }
            Ext.Ajax.request(
                {
                    url: '/EmpProfile.mvc/ChgPwd',
                    waitMsg: '数据正在提交，请耐心等待...',
                    waitTitle: '请等待',
                    method: 'POST',
                    params:
                        {
                            oldPwd: pwdForm.form.findField('oldPwd').getValue(),
                            newPwd: pwdForm.form.findField('newPwd').getValue()
                        },
                    success: function(response, options) {
                        var responseMessage = Ext.JSON.decode(response.responseText);
                        if (responseMessage.Result) {
                            Ext.getCmp('pwdWin').close();
                            Ext.MessageBox.alert("消息", "密码修改成功!");
                        } else {
                            Ext.MessageBox.alert("消息", responseMessage.Message);
                        }
                    },
                    failure: function (response, options) {
                        var responseMessage = Ext.JSON.decode(response.responseText);
                        Ext.MessageBox.show({
                            title: "修改失败",
                            msg: responseMessage.Message
                        });
                    }
                });
        }
    }, { text: '取消', id: 'btnCancel',
        handler: function () {
            Ext.getCmp('pwdWin').close();
        }
    }],
    items: [{
        xtype: 'form', id: 'pwdForm', labelWidth:60, border: false,
        items: [{
            xtype: 'textfield', fieldLabel: '原密码', name: 'oldPwd', id: 'oldPwd', anchor: '-10',
            inputType: 'password', allowBlank: false, blankText: '请填写原始密码'
        }, {
            xtype: 'textfield', fieldLabel: '新密码', name: 'newPwd', id: 'newPwd', anchor: '-10',
            inputType: 'password', allowBlank: false, blankText: '请填写新密码'
        }, {
            xtype: 'textfield', fieldLabel: '确认新密码', name: 'surePwd', id: 'surePwd', anchor: '-10',
            inputType: 'password', allowBlank: false, blankText: '请再次填写新密码'
        }]
    }]
});